/*
 * @Author: your name
 * @Date: 2024-04-18 11:02:42
 * @LastEditTime: 2024-04-18 11:15:45
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \.leetcode\429.n-叉树的层序遍历.cpp
 */
/*
 * @lc app=leetcode.cn id=429 lang=cpp
 *
 * [429] N 叉树的层序遍历
 */

// @lc code=start
/*
// Definition for a Node.
class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
*/

class Solution {
public:
    vector<vector<int>> levelOrder(Node* root) {
        // 定义返回值
        vector<vector<int>> res;
        if(root == nullptr){
            return res;
        }
        // 定义队列
        queue<Node*> que;
        que.push(root);
        while(!que.empty()){
            // 每一层的数组
            vector<int> vec;
            int size = que.size();
            for(int i = 0; i < size; i++){
                // 获取队列头并弹出队列
                Node* tmp_node = que.front();
                que.pop();
                vec.push_back(tmp_node->val);
                for(auto child:tmp_node->children){
                    que.push(child);
                }
            }
            res.push_back(vec);

        }
        return res;
    }
};
// @lc code=end

